package carmensd.vista

import org.uqbar.arena.windows.WindowOwner
import org.uqbar.arena.widgets.Panel
import org.uqbar.arena.aop.windows.TransactionalDialog
import applicationModel.EditarConexionesAppModel
import org.uqbar.arena.layout.VerticalLayout
import org.uqbar.arena.widgets.Selector
import org.uqbar.arena.widgets.Button
import org.uqbar.arena.widgets.List
import org.uqbar.arena.layout.HorizontalLayout
import org.uqbar.arena.bindings.PropertyAdapter
import modelo.Pais

class EditarConexionesWindow extends TransactionalDialog<EditarConexionesAppModel>{
	
	new(WindowOwner owner, EditarConexionesAppModel model) {
		super(owner, model)
	}
	
	override protected addActions(Panel panel) {
	}
	
	override protected createFormPanel(Panel panel) {
		this.setTitle = "Editar conexiones de:"
		panel.setLayout(new VerticalLayout())
		
		colocarLista(panel, "paisElegido.paisesConConexionAerea", "paisSeleccionado")
		new Button(panel) => [
			caption = "Eliminar";
			onClick [|this.modelObject.eliminarConexion()];
		]
		
		this.componentesParaAgregar(panel)
	}
	
	def componentesParaAgregar(Panel panel) {
		
		var Panel panelInterno = new Panel(panel)
		panelInterno.setLayout(new HorizontalLayout())
		new Selector(panelInterno) =>[
			var binding = bindItemsToProperty("mapamundi.listaPaises")
            binding.setAdapter(new PropertyAdapter(typeof(Pais), "nombre"))
//			bindItemsToProperty("mapamundi.listaPaises")
			bindValueToProperty("conexionElegida")
		]
		new Button(panelInterno) => [
			caption = "Agregar";
			onClick [|this.modelObject.agregarConexion()
				this.close()
			];
		]
	}
	
	def colocarLista(Panel nuevoVillanoPanel, String propiedadDelDominio, String propiedad) {
			new List(nuevoVillanoPanel) => [
				width = 90
				height = 90
				allowNull(true)
				bindItemsToProperty(propiedadDelDominio)
				bindValueToProperty(propiedad)
			]
	}
	
}